<template>
	<!-- 员工详情 -->
  <div class="stu">
	 <el-dialog v-loading="loading"  :title="num==0?'新增前端用户信息':'修改前端用户信息'" :visible.sync="dialogVisible" width="35%" :before-close="handleClose"  :close-on-click-modal='false'>
	   <!-- <p class="pbox" style="text-align: center;width:100%;font-size:30px;height:40px;">员工信息详情</p> -->
	    <div style="width:600px;margin: 0 auto;padding-bottom:20px;">
			<div style="margin-top:10px;" class="tabbox">
					<p style=""><a style="color:red;">* </a>选择行政区域</p>
					<el-select :disabled='num==1' style="width:75%;border:none;" class="pboxc1" v-model="activess.village_name" @change='activess.cadre_id="";activess.name="";git_gan()' clearable filterable placeholder="请选择">
					  <el-option v-for='item in $store.state.cunid' :key='item.label' :label="item.label" :value="item.label"></el-option>
					</el-select>
			</div>
			<div style="margin-top:10px;" class="tabbox" v-show='num!=1'>
					<p style=""><a style="color:red;">* </a>选择干部</p>
					<el-select :disabled='num==1' style="width:75%;border:none;" @change='gans' class="pboxc1" v-model="activess.cadre_id" clearable filterable placeholder="请选择">
					  <el-option v-for='item in ganb' :key='item.id' :label="item.name" :value="item.id"></el-option>
					</el-select>
			</div>
			
			<div style="margin-top:10px;" class="tabbox" v-show="num==1">
					<p style=""><a style="color:red;">* </a>选择干部</p>
					<el-input :disabled='num==1' style='width:75%;' placeholder="请输入" v-model="activess.user_name" clearable></el-input>
			</div>
			
			<div style="margin-top:10px;" class="tabbox">
					<p style=""><a style="color:red;">* </a>账号</p>
					<el-input disabled style='width:75%;' placeholder="请输入" v-model="activess.name" clearable></el-input>
			</div>
			<div v-show="jx!=2" style="margin-top:10px;" class="tabbox">
					<p style=""><a style="color:red;">* </a>密码</p>
					<el-input style='width:75%;' placeholder="请输入" v-model="activess.password" type='password' clearable></el-input>
			</div>
			<div v-show="jx!=2" style="margin-top:10px;" class="tabbox">
					<p style=""><a style="color:red;">* </a>确认密码</p>
					<el-input style='width:75%;' placeholder="请输入" v-model="activess.password_confirm" type='password' clearable></el-input>
			</div>
			<div v-show="jx!=3" style="margin-top:10px;" class="tabbox">
					<p style=""><a style="color:red;">* </a>审批权限</p>
					<el-select  style="width:75%;border:none;" class="pboxc1" @change='shen' v-model="activess.power" clearable placeholder="请选择">
					  <el-option v-for='item in $store.state.sxdb' :label="item.label" :value="item.value"></el-option>
					</el-select>
			</div>
		</div>	
		<div style="width:100%;height:40px;margin-top:20px;">
	      <div style="width:170px;margin: 0 auto;">
	        <el-button type="danger" @click="handleClose">取 消</el-button>
	        <el-button type="primary" style='float:right;' @click="git_acts">确 定</el-button>
	      </div>
		</div>
	 </el-dialog>
  </div>
</template>

<script>
import $ from 'jquery'
export default {
  name: 'stu',
  components: {},//声明子组件
  computed:{
	  activeput(){//联动判断，code 为上一级的code  act为当前未赛选的数据字典
	  	return function(code,act){
	  		let a = [];
	  		for(let i=0;i<act.length;i++){
	  			if(act[i].own_code==code){
	  				a.push(act[i]);
	  			}
	  		}
	  		return a;
	  	}
	  },
	  gitcode(){//通过id获取code
	  	return function(id,act){
	  		for(let i=0;i<act.length;i++){
	  			if(id==act[i].label){
	  				return act[i].code;
	  			    break
	  			}
	  		}
	  	}
	  },
  },
  data(){
	  return {
		loading:false,
		btn_shou:false,
		dialogVisible: false,
		activess:{
				      name:'',//账号
				      password:'',//密码
					  cadre_id:'',//干部ID
					  power:'',//权限
					  password_confirm:'',//二次密码
					  village_name:'',
					  user_name:'',
		},
		
		renbox:[],
		num:0,     
		ganbox:[],//干部数据列表
		pkhbox:[],//平困户数据表
		jx:2,//区分修改密码和修改权限
		ganb:[],
	  }
  },
  methods:{
	  shen(i,j){
		  // console.log(i,j);
		  // if(i[i.length-1]==1){
			 //  this.activess.power = [];this.activess.power.push(1);
		  // }else if(i[0]==1){
			 //  this.activess.power.splice(0,1);
		  // }
	  },
	  gans(i){
		 for(let j in this.ganb){
			 if(this.ganb[j].id==i){
				 this.activess.name = this.ganb[j].phone;
			 }
		 }
	  },
	  obtainValue(value){
		 console.log(this.activess.cadre_id);  
	  },
	  
	  git_gan(){
		  $.ajax({url:'/dj/convent_service/get_cadres_list',type:'post',
		            data:{
						village_name:(this.activess.village_name=='新丰街道')?'新丰乡':this.activess.village_name,
						page:1,
						size:10000
					},
					dataType:'json',success:(res)=> {
		  			if(Object.prototype.toString.call(res) != '[object Object]'){res = JSON.parse(res)}
		  			 if(res.code==200){
		  				 this.ganb = res.data;
		  				 console.log(this.ganb,'干部列表');
		  			 }
		  }})
		  
	  },
	  
	  git_act(i,num,j){//获取数据的同打开狂口
	     console.log(i,num,j);
	  
	      if(num==1){
			  console.log(this.activess,i);
			  this.activess={
			  		      name:i.name,//账号
			  		      password:'',//密码
			  			  cadre_id:i.cadre_id,//干部ID
			  			  // power:this.string_array_nmb(i.power),//权限
						  power:Number(i.power),//权限
			  			  password_confirm:'',//二次密码
						  id:i.id,
						  village_name:i.village_name,
						  user_name:i.user_name
			  }
			  // this.activess = i;
			  // this.activess.password = '';
			  // this.activess.power = this.activess.power.split(',');
			  this.git_gan();
		  }
		  this.num = num;
		  this.jx = j;
	      this.dialogVisible=true;
	  },
	  git_acts(){//提交数据
	        console.log(this.activess)
			
		   if(this.jx!=2&&this.jx!=3){
			if(this.isNull(this.activess.village_name)){this.$message.error('请选择 行政区域');return false}
		   }
	        if(this.isNull(this.activess.cadre_id)){this.$message.error('请选择 干部');return false}
			if(this.isNull(this.activess.name)){this.$message.error('请输入 账号');return false};
		   if(this.num==0||this.jx==3){
			if(this.isNull(this.activess.password)){this.$message.error('请输入 密码');return false};
			if(this.isNull(this.activess.password_confirm)){this.$message.error('请输入 确认密码');return false};
			if(this.activess.password==this.activess.password_confirm){}else{this.$message.error('两次输入的密码不同');return false};
		   }
			// if(this.activess.power.length==0){this.$message.error('请选择 审批权限');return false}
			if(this.isNull(this.activess.power)){this.$message.error('请选择 审批权限');return false}
			
			// this.activess.power = this.activess.power.join(',');
	  		 let url = this.num==1?'/dj/convent_service/front_modify':'/dj/convent_service/front_insert';
	  		 $.ajax({url:url,type:'post',data:this.activess,dataType:'json',success:(res)=> {
	  		 	if(Object.prototype.toString.call(res) != '[object Object]'){res = JSON.parse(res)}
	  		 	 console.log(res,'提交');
	  		 	 if(res.code==200){
	  				this.$parent.git_act();
	  		 		this.$message({message: '操作成功',type: 'success'});
	  		 		this.dialogVisible=false;
	  				this.qin();
	  		 	  }else{
	  		 		this.$message.error(res.msg);
	  		 	  }
	  		 	}
	  		 })
	  },
	  qin(){//清除
	  	this.activess={
				name:'',//账号
				password:'',//密码
				cadre_id:'',//干部ID
				power:'',//权限
				password_confirm:'',//二次密码
				village_name:'',
				user_name:'',
		}
		this.ganbox=[];//干部数据列表
		this.pkhbox=[];//平困户数据表
	  },
	  
	  handleClose(done){//监测用户点击x
	     this.$confirm('确定取消关闭吗？','提示',{confirmButtonText:'确定',cancelButtonText:'取消',type: 'warning'
	     }).then(() => {
	  	   this.dialogVisible = false;
	  	   this.qin();
		   this.$parent.git_act();
	  	}).catch(() => {});
	  },
  },
  mounted(){
	  
  }
}
</script>
<style scoped="scoped">
	
	.pboxc1{
		float:left;
		width:70%;
		height:40px;
		border:1px solid rgba(242,242,242,1);
		font-size:14px;color:#666666;
		/* padding-left:18px; */
		text-align:left;
		/* overflow: hidden; */
		/* text-overflow:ellipsis; */
		/* white-space: nowrap; */
	}
	.tabbox{
		width:100%;
		height:40px;
		line-height: 30px;
		margin-top:23px;
	}
	.tabbox p{
		font-size:14px;
		color:#000000;
		width:17%;
		text-align:right;
		margin-right:28px;
		float:left;
		overflow: hidden;
		text-overflow:ellipsis;
		white-space: nowrap;
		font-family:Source Han Sans CN;
	}
	.pbox{
		width:10%;
		text-align:right;
		height:26px;
		margin-bottom:20px;
		font-size:18px;
		color:#000101;
		overflow: hidden;
		text-overflow:ellipsis;
		white-space: nowrap;
		font-family:Source Han Sans CN;
		font-weight:600;
	}
</style>
